/**
 * Created by xieky on 2017/6/22.
 */
define(function (require, exports, module) {
    var angular = require('angular');
    require("pagination");
    require("angular-ui");
    require('/public/js/myservice/common/nav');
    var authorize = require('/public/js/myservice/authorize');
    var config = require('/public/js/myservice/config');
    require('/public/js/myservice/contract/contract-common');
    var util = require("util");
    var api_prefix = G_CONFIG["api_prefix"]; //api前缀
    require('/public/js/myservice/common/row-toolbar');

    angular.module('mytest',['ngUI','myNav','ContractCommonService','rowToolbar'])
        .service('testtService',['$rootScope', function ($rootScope) {
            var service={
                onTestShow: function ($dialog, $dialogScope, invoiceType, contractID) {

                    $dialogScope.contract_id = contractID;

                    $dialogScope.ddlConfigContractCategory={
                        allowClear: false,
                        data: [{id: 1, text: '服务票'}],
                        minimumResultsForSearch: 'Infinity'
                    };

                    //初始化信息
                    $dialogScope.contractInfo = {
                        contract_amount:1100,
                        editMode:1,
                        contract_name:'最佳合同'
                    };

                    $dialogScope.$watch('contract_name', function (ivalue) {
                        util.alert(ivalue);
                    });
                },
                editTestSave:function($data, $dialog, $dialogScope, callback, pageIndex){
                    //util.alert($data.name);
                }
            };

            return service;
        }])
        .controller('mytestListCtrl',['$scope','testtService','contractCommonService','appservice',function($scope,testtService,contractCommonService,appservice){
            appservice.name = '明源云链-TEST';
            $scope.testtService = testtService;

            $scope.testtService

            $scope.filterDataStatus= [
                {name: '全部', selected: true, value: ''},
                {name: '草稿', value: '0'},
                {name: '未审核', value: '1'},
                {name: '已审核', value: '2'},
                {name: '作废', value: '-1'}
            ];
            $scope.filterDataNature=[
                {name:'全部',selected: true, value:'0'},
                {name:'附属合同',value:'1'},
                {name:'独立合同',value:'2'},
            ];
            $scope.filterDataCities=[
                {areaName:'全部',value:'0'}
            ];

            //获取合同区域列表
            contractCommonService.getContractAreas(function (data) {
                $.merge($scope.filterDataCities, data);
                $scope.$applyAsync();
            });

            //查询执行
            $scope.getData={
                keyword: '',
                doExecute:function(pageindex){
                    var parms = $scope.getQueryParams(pageindex);
                    //var parms = {};
                    //prams.filterStates='2';
                    var url = api_prefix + "/contract/get-contract-list";
                    util.myAjax({
                        url:url,
                        type:"GET",
                        context:this,
                        data:parms,
                        success:function(resultdata){
                            $scope.contractlist = resultdata.data.items;
                            $scope.$applyAsync();
                            //util.alert('合同列表获取成功');
                        }
                    });
                }
            };

            $scope.getQueryParams= function (pageindex) {
                var param = {keyword: $scope.getData.keyword};
                param.pageindex = pageindex == null?1:pageindex;
                param.pagesize = 10;

                filterStatus = $.grep($scope.filterDataStatus, function (obj,idx) {
                    return obj.selected == 1;
                })
                if(filterStatus.length){
                    param.status = filterStatus[0].value;
                }

                return param;
            };


            $scope.getData.doExecute();

            $scope.post2data = function(pp) {
                util.myAjax({
                    url:'http://119.29.161.190/api/picture/router?handler=recognizeorgcertificate',
                    type:"POST",
                    context:this,
                    data:[],
                    success:function(resultdata){
                        util.alert(resultdata);
                    },
                    error:function(ex){
                        util.alert(ex.Message);
                    }
                });
            };

            $scope.post2data();

        }])
})